import { seq } from "../db"
import { DataTypes, Model, Optional } from "sequelize"
import * as path from "path"
//权限等级分两种，一种最高权限，一种普通权限
enum roleType {
    BOSS = "boss",
    ADMIN = "admin"
}
const roles = ["admin", "boss"]

interface IUserBase {
    userName: string
    password: string
    nickname: string
    isDM:boolean
    isGame:boolean
    gameId:number 
    gameName:string
    role: roleType
    is_deleted?: boolean
}

interface IUserInstance extends Model {
    id:number
    userName: string
    password: string
    nickname: string
    avatar: string
    isDM:boolean
    isGame:boolean
    gameId:number 
    gameName:string
    role: roleType
    is_deleted?: boolean

}








const UserModel = seq.define<IUserInstance>('User', {
    // 在这里定义模型属性
    userName: {
        type: DataTypes.STRING,
        comment: "用户名",
        unique: true,
        allowNull: false
    },
    password: {
        type: DataTypes.STRING,
        allowNull: false,
        comment: "密码"
        // allowNull 默认为 true
    },
    role: {
        type: DataTypes.ENUM,
        values: roles,
        defaultValue: roleType.ADMIN,
        comment: "两种身份，默认是admin"
    },
    nickname: {
        type: DataTypes.STRING,
        defaultValue: "默认昵称",
        comment: "用户昵称"
    },
    avatar: {
        type: DataTypes.STRING,
        defaultValue: "",
        comment: "用户头像"
    },
    gameName:{
        type: DataTypes.STRING,
        allowNull: true
    },
    sex: {
        type: DataTypes.BOOLEAN,
        defaultValue:true,
        comment: "性别"
    },
    isDM:{
        type:DataTypes.BOOLEAN,
        defaultValue:false,
    },
    gameId:{
        type: DataTypes.INTEGER,
        allowNull: true
    },
    isGame: {
        type:DataTypes.BOOLEAN,
        defaultValue:false,
    },
    is_deleted: {
        type: DataTypes.BOOLEAN,
        defaultValue: false,
        comment: "是否删除，默认不删除"

    }

}, {
    // 这是其他模型参数
    tableName: 'users'
});






export {
    UserModel,
    IUserInstance,
    roleType,
    IUserBase
}








